<!--
 * @Date: 2022-01-13 10:50:47
 * @LastEditors: 邓春宜
 * @Desc: 
 * @LastEditTime: 2022-01-20 17:40:17
 * @FilePath: \views\print.html
-->
<!doctype html>
<html>

<head>
    <meta charset='UTF-8'>
    <meta name='viewport' content='width=device-width initial-scale=1'>
    <title>打印</title>
    <style type='text/css'>
        .line {
            margin-bottom: 10px;
            display: inline-block;
            width: 50%;
        }

        .tags span {
            font-size: 20px;
            border-radius: 3px;
            padding: 3px 5px;
            background-color: rgb(9, 146, 66);
            border: 2px solid rgb(9, 146, 66);
            color: #fff;
            margin-left: 10px;
            cursor: pointer;
        }
        .tags span.active { border: 2px solid rgb(206, 37, 37);}

        .sub {font-size: 20px;
            border-radius: 3px;
            padding: 6px 5px;
            text-align: center;
            background-color: rgb(9, 146, 66);  color: #fff;cursor: pointer;}
    </style>
    <script src="static/jquery.min.js"></script>
</head>

<body class='typora-export os-windows'>

    <h2>请选择称</h2> 
    
    <div class="tags"></div>

    <h2>备注：</h2>
     <textarea id="beizhu" rows="15" style="width: 100%;"></textarea>
     
    <div class="sub">提交</div>
</body>
<script>
 
Date.prototype.Format = function (fmt) {
    var o = {
        "M+": this.getMonth() + 1, //月份 
        "d+": this.getDate(), //日 
        "H+": this.getHours(), //小时 
        "m+": this.getMinutes(), //分 
        "s+": this.getSeconds(), //秒 
        "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
        "S": this.getMilliseconds() //毫秒 
    };
    if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
    return fmt;
}
  

    var readpoints = [] ;
    var readdoms = [] ;
    var tags = [
    {name:"aaa1",tag:'@ClientCount'},
    {name:"aaa2",tag:'@ClientCount'}
    ];
    $.each(tags, function (i, v) { 
        $('.tags').append(`<span data-tag="${v.tag}">${v.name}</span>`);
    });
    $('.tags span').click(function(e){
        $(e.target).addClass('active').siblings().removeClass('active')     
    })

    $('.sub').click(function(e){
        let act = $('.tags span.active') ;
        if (act.length ==0) {
            alert('请选择称！')
            return false;
        }
        console.log(act.data('tag'));
        console.log(act.html());  
        //读取点位
        $.post("/api/opc/read", {tags:act.data('tag')},
             function (re, textStatus, jqXHR) { 
               
                if (re.code==0) { 
                    console.log(re.data);
                    var datestring = new Date().Format("yyyy-MM-dd HH:mm");
                    let printdata = {
                        title:"物料信息",
                        contents:[
                          '时间：'+datestring ,
                          '重量：'+re.data+'kg',
                          '位置：'+act.html(),
                          '备注：'+$('#beizhu').val()
                        ]
                    }
                    //执行打印
                    $.post("/api/print/run", printdata, function (re2, textStatus, jqXHR) { 
                        if (re2.code==0) {
                            alert('打印成功')
                        }else{
                            alert('打印失败'+re2.msg) 
                        }
                    })



                }else{
                    alert('异常'+re.msg)
                }
             })
 

       
    })



     

      


</script>

</html>